package com.github.thinwonton.example.apidoc.controller;

import com.github.thinwonton.example.apidoc.common.Result;
import com.github.thinwonton.example.apidoc.controller.product.param.VideoStructuredAnalysisTasksDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.io.IOUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Date;

@Tag(name = "测试用例")
@RestController
public class Example2021922Controller {

    @Operation(summary = "example2021922")
    @PostMapping("example2021922")
    public ResponseEntity a(@RequestBody VideoStructuredAnalysisTasksDTO dto) {
        return null;
    }


    @Operation(summary = "delete method with body")
    @DeleteMapping("2021111/delete")
    public Result delete(HttpServletRequest request) {
        try {
            ServletInputStream inputStream = request.getInputStream();
            String body = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
            return Result.ok(body);
        } catch (IOException e) {
            e.printStackTrace();
            return Result.error("参数错误");
        }
    }

    /**
     * 2021111/400?date=2021-11-233
     *
     * @return
     */
    @Operation(summary = "模拟400错误")
    @GetMapping("2021111/400")
    public Result error400(@Schema(description = "日期", example = "2021-11-233") Date date) {
        return Result.ok(date);
    }

}
